<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-button type="primary" @click="onNewFlow" style="margin-bottom: 20px"
      >新增流程</el-button
    >
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column label="套名" align="center" prop="title">
      </el-table-column>
      <el-table-column
        label="进度"
        align="center"
        prop="steplist"
        width="1000px"
      >
        <template slot-scope="{ row }">
          <div style="padding: 20px 0">
            <el-steps
              :space="200"
              :active="0"
              align-center
              style="margin-bottom: 20px"
            >
              <el-step
                :title="item.name"
                v-for="(item, index) in row.steplist"
                :key="index"
              ></el-step>
            </el-steps>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <el-button type="text" style="color: red" @click="onDelete(row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminApiGetJointlystep"
    />
  </div>
</template>

<script>
import { postAdminApiGetJointlystep, postAdminApiDelJointlystep } from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      form: {
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
    };
  },
  activated() {
    let form = this.form;
    this.postAdminApiGetJointlystep(form);
  },
  methods: {
    // 删除
    onDelete(id) {
      let that = this;
      let obj = {
        id,
      };
      this.$confirm("确定删除此流程?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postAdminApiDelJointlystep(obj).then((res) => {
            let form = that.form;
            that.postAdminApiGetJointlystep(form);
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    onNewFlow() {
      this.$router.push({ name: "LayoutAdminFlowPathNewFlow" });
    },
    // 采购列表
    async postAdminApiGetJointlystep(data) {
      this.loading = true;
      this.form = data;
      postAdminApiGetJointlystep(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      console.log("this.form", this.form);
      this.postAdminApiGetJointlystep(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
